home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / adatimer.zip / TIMEL6.ADA < prev    next >
Text File  |  1990-06-07  |  2KB  |  78 lines

  1. -- Listing 6. Slow timer demo program.
  2.  
  3. with POLLED_TIMER;
  4. with DIM_FLOAT, ASCII_UTILITIES;
  5.   -- from Ada in Action by Do-While Jones.
  6. with TEXT_IO;
  7. procedure Slow_Polled_Timer_Demo is
  8.   type Seconds is new DIM_FLOAT.Units;
  9.  
  10.   USED, LEFT : Seconds;
  11.  
  12.   package TIMER is new POLLED_TIMER(Seconds);
  13.  
  14.   procedure Put(TIME : Seconds) is
  15.   begin
  16.     TEXT_IO.Put(ASCII_UTILITIES.Fixed_Image
  17.       (Dimensionless(TIME)));
  18.   end Put;
  19.  
  20. begin
  21.   TEXT_IO.Put_Line("Slow Polled Timer Demo");
  22.   -- Show single mode
  23.   TIMER.Set(+2.0,TIMER.SINGLE);
  24.   TEXT_IO.Put_Line("Starting 2 second timer.");
  25.   TIMER.Start;
  26.   while not TIMER.Has_Expired loop null; end loop;
  27.   TEXT_IO.Put_Line("Timer has expired.");
  28.   -- Show reset and read-on-the-fly
  29.   TEXT_IO.Put_Line("Reading the timer on the fly.");
  30.   TIMER.Restart;
  31.   Delay(0.5);
  32.   USED := TIMER.Time_Used;
  33.   LEFT := TIMER.Time_Left;
  34.   Put(USED); TEXT_IO.Put_Line(" seconds used.");
  35.   Put(LEFT); TEXT_IO.Put_Line(" seconds left.");
  36.   Delay(1.0);
  37.   USED := TIMER.Time_Used;
  38.   LEFT := TIMER.Time_Left;
  39.   Put(USED); TEXT_IO.Put_Line(" seconds used.");
  40.   Put(LEFT); TEXT_IO.Put_Line(" seconds left.");
  41.   -- Show Stop and read while stopped.
  42.   TEXT_IO.Put_Line("Reading the timer when stopped.");
  43.   TEXT_IO.Put_Line("2 second timer started.");
  44.   TIMER.Restart;
  45.   Delay(0.5);
  46.   TIMER.Stop;
  47.   TEXT_IO.Put_Line("Stopped after 1/2 second.");
  48.   USED := TIMER.Time_Used;
  49.   LEFT := TIMER.Time_Left;
  50.   Put(USED); TEXT_IO.Put_Line(" seconds used.");
  51.   Put(LEFT); TEXT_IO.Put_Line(" seconds left.");
  52.   Delay(1.0);
  53.   TEXT_IO.Put_Line("1 second later.");
  54.   USED := TIMER.Time_Used;
  55.   LEFT := TIMER.Time_Left;
  56.   Put(USED); TEXT_IO.Put_Line(" seconds used.");
  57.   Put(LEFT); TEXT_IO.Put_Line(" seconds left.");
  58.   TEXT_IO.Put_Line("Let it run another 0.2 seconds.");
  59.   TIMER.Start;
  60.   Delay(0.2);
  61.   USED := TIMER.Time_Used;
  62.   LEFT := TIMER.Time_Left;
  63.   Put(USED); TEXT_IO.Put_Line(" seconds used.");
  64.   Put(LEFT); TEXT_IO.Put_Line(" seconds left.");
  65.   -- Show repeat mode
  66.   TIMER.Set(+1.0,TIMER.REPEATED);
  67.   TEXT_IO.Put_Line
  68.     ("Watching 1 second timer for 5 seconds.");
  69.   TIMER.Start;
  70.   for i in 1..5 loop
  71.     while not TIMER.Has_Expired loop null; end loop;
  72.     TEXT_IO.Put_Line(" Tick");
  73.   end loop;
  74.   TIMER.Stop;
  75.   TEXT_IO.New_Line;
  76.   TEXT_IO.Put_Line("Done.");
  77. end Slow_Polled_Timer_Demo;
  78.